package com.imooc.exception;

import com.imooc.grace.result.ResponseStatusEnum;

/**
 * @Description : 自定义异常，统一处理异常信息。便于解耦，
 *                  Service 与 Controller 错误的解耦，
 *                  不会被 Service 的返回类型所限制
 *
 *                  继承 RuntimeException，没有侵入性
 *                  如果继承 Exception，则代码中需要使用 try/catch 进行捕获
 * @Author : YTY
 * @Date : 2020-11-29 08:45
 */
public class MyCustomException extends RuntimeException {

    private ResponseStatusEnum responseStatusEnum;

    public MyCustomException(ResponseStatusEnum responseStatusEnum) {

        super("异常状态码为：" + responseStatusEnum.status()
                + "；具体异常信息为：" + responseStatusEnum.msg());
        this.responseStatusEnum = responseStatusEnum;
    }

    public ResponseStatusEnum getResponseStatusEnum() {
        return responseStatusEnum;
    }

    public void setResponseStatusEnum(ResponseStatusEnum responseStatusEnum) {
        this.responseStatusEnum = responseStatusEnum;
    }
}
